package pre;


/**
 * @program: leetcode
 * @author: jzhou
 * @date: 2022-11-16 18:14
 * @version: 1.0
 * @description: 单例设计模式
 **/
public class Singleton {

    private static volatile Singleton INSTANCE;
    private Singleton(){}

    public static Singleton getInstance(){
        if (INSTANCE == null){
            synchronized (Singleton.class){
                if (INSTANCE == null)
                    INSTANCE = new Singleton();
            }
        }
        return INSTANCE;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            new Thread(() -> System.out.println(Singleton.getInstance().hashCode())).start();
        }
    }


}
